﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace VKontakteClient
{
    /// <summary>
    /// Interaction logic for AudioSearchControl.xaml
    /// </summary>
    public partial class AudioSearchControl : UserControl
    {
        public AudioSearchControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Событие, вызываемое при необходимости перехода на страницу пользователя
        /// </summary>
        public event Main.ChangePageDelegate ChangePageEventHandler;

        /// <summary>
        /// Обработчик смены контекста данных
        /// </summary>
        private void DCChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var h = DataContext as AudioSearcher;
            SearchTextBox.Text = h.StringToSearch;
            CheckBox_Unchecked(sender, null);
        }

        /// <summary>
        /// Поиск аудиозаписей
        /// </summary>
        private void Search(object sender, RoutedEventArgs e)
        {
            if (ChangePageEventHandler != null)
                ChangePageEventHandler("http://vkontakte.ru/audiosearch.php?q="+SearchTextBox.Text);
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            var h = DataContext as AudioSearcher;
            audios.SetBinding(ListBox.ItemsSourceProperty, new Binding()
            {
                Source = h,
                Path = new PropertyPath("ClearAudioList")
            });
        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            var h = DataContext as AudioSearcher;
            audios.SetBinding(ListBox.ItemsSourceProperty, new Binding()
            {
                Source = h,
                Path = new PropertyPath("NormalAudioList")
            });
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var h = DataContext as AudioSearcher;
            if (h != null)
                h.LoadAll();
        }
    }
}
